<template>
  <view v-if="hasPermission">
    <slot/>
  </view>
</template>

<script>
import store from '@/store'
export default {
  name: 'index',
  props: {
    // 权限码，传多权限码用逗号拼接
    code: {
      type: String,
      default: ''
    },
    // 传多权限码时，or：有部分权限即可；and：必须有全部权限
    type: {
      type: String,
      default: 'or'
    }
  },
  computed: {
    permissions() {
      return store.getters.permissions
    },
    hasPermission() {
      const codeStr = this.code.trim().replace(/\s+/g, '')
      const codeArr = codeStr.split(',')
      if (this.type === 'or') {
        return this.$checkModules(codeArr)
      }
      return codeArr.every(item => this.$checkModule(item))
    }
  },
  methods: {
  }
}

</script>

<style scoped lang="scss">

</style>
